<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
    <link href="${path}/assets/hplus/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
	<link href="${path}/assets/publicSecurity/css/gonganQuery.css" rel="stylesheet">
	

</head>
<body>

	<!-- 顶部导航结束 -->
    <div class="wrapper wrapper-content  animated fadeInRight" >
        <div class="row" id="test01">
            <div >
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5></h5>

                    </div>
                    <input type="hidden" value="${imgurl}" id="imgurl">
                    <input type="text" class="form-control" id="url"></input>
                    <div class="ibox-content">
                        <form action="${path}/material/query" method="post" role="form" class="form-inline query-form">
                            <div class="form-group">
                                <label  class="sr-only">类型</label>
                                <input name="name" class="form-control" id="name" placeholder="素材名称">
                            </div>
                            <button type="button" id="btn-query" class="btn btn-primary">查询</button>
                            <button type="button" id="btn-add" class="btn btn-success fr">添加素材</button>
                        </form>
                        <div class="jqGrid_wrapper">
                            <table id="table_user"></table>
                            <div id="pager_user"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	

    <%@include file="/WEB-INF/common/hplus-js.jsp"%>

    <script type="text/javascript">


        $(document).ready(function () {

            var types = [];

            $.ajax({
                url:'${path}/regenerant/gettypes',
                type:'GET',
                dataType:'json',
                success:function(json){
                    types = json;
                }
            });


            $.jgrid.defaults.styleUI = 'Bootstrap';
            $("#table_user").jqGrid({
            	url : "${path}/material/query",
                mtype : "POST",
                datatype : "JSON",
                jsonReader:{
                   	id: "id", //相当于设置主键
		           	root: "result",//Json数据
		           	total: "allPage",//总页数
					page: "page", //当前页
					records: "allCount",//总记录数
					repeatitems: false
                },
                altRows: true,//单双行样式不同
                altclass: 'differ',
                autowidth: true,
                shrinkToFit: true,
                height:353,
                rowNum: 10,
                rowList: [10, 20, 30],
                colNames: ['名称','原文件名称','添加时间', '备注','操作'],
                colModel: [{
                        name: 'name',
                        index: 'name',
                        width: 20
                    },{
                    name: 'nameA',
                    index: 'nameA',
                    width: 20
                    },{
                        name: 'createDate',
                        index: 'createDate',
                        width: 20
                    },{
                        name: 'remark',
                        index: 'remark',
                        width: 35
                    },{
                    name: 'id',
                    index: 'id',
                    width: 35,
                    formatter:function(cellvalue, options, rowObject){
                            var html = "<a class='btn btn-sm btn-danger' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"del('"+cellvalue+"')\">删除</a>";
                                html += "<a class='btn btn-w-m btn-primary' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"edit('"+cellvalue+"')\">修改</a>";
                                html += "<a class='btn btn-w-m btn-primary' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"copyUrl('"+cellvalue+"')\">复制地址</a>";
                                html += "<a class='btn btn-w-m btn-primary' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"det('"+cellvalue+"')\">查看</a>";
                            return html;
                    }
                }
                ],
                pager: "#pager_user",
                viewrecords: true,
                hidegrid: false,
                loadonce: true
            });
            $(window).bind('resize', function () {
                var width = $('.jqGrid_wrapper').width();
                $('#table_user').setGridWidth(width);
            });
            $(window).trigger("resize");
            $("#btn-add").click(function(){
            	layer.open({
                    type: 2,
                    title: '添加素材',
                    shadeClose: false,
                    shade: 0.5,
                    area: ['70%', '60%'],
                    content: '${path}/material/add' //iframe的url
                });
            });

            $("#btn-query").click(function(){
            	$("#table_user").jqGrid('setGridParam', {
                    url : "${path}/material/query",
                    datatype:'json',
                    postData : {
                    	"name":$("#name").val(),
                    },
                    page : 1
                }).trigger("reloadGrid"); //重新载入
            });
        });
        function download(url){

        }

        function edit(id){
            layer.open({
                type: 2,
                title: '修改',
                shadeClose: false,
                shade: 0.5,
                area: ['70%', '60%'],
                content: '${path}/material/edit?id='+id //iframe的url
            });
        }

        function det(id){
            layer.open({
                type: 2,
                title: '详情',
                shadeClose: false,
                shade: 0.5,
                area: ['70%', '60%'],
                content: '${path}/material/det?id='+id //iframe的url
            });
        }


        function del(id){
            var op = ("删除");
            layer.confirm("您确定要"+op+"该物品吗? ", {
                btn: ['确定','取消'], //按钮
                shade: true, //不显示遮罩
                shadeClose: true,
                shade: 0.5,
            }, function(){
                console.log("确定")
                $.ajax({
                    type: "POST",
                    url: "${path}/material/del",
                    data:{"id":id},
                    dataType: "json",
                    success: function(json){
                        var code = json.code;
                        if (code==0){
                            layer.msg("删除成功",{icon:1})
                            setTimeout(function(){
                                layer.closeAll();
                                window.location.reload();
                            },1000);
                        }else{
                            layer.msg("删除失败",{icon:5})
                            setTimeout(function(){
                                window.location.reload();
                            },1000);
                        }
                    }

                });
            },function(){
                console.log("取消")

            });


        }

        function copyUrl(id) {
            var url = $("#imgurl").val();
            $("#url").val(url+id);
            var el = document.getElementById("url");
            el.select(); // 选择对象
            document.execCommand("Copy"); // 执行浏览器复制命令
            layer.msg("已复制好，可贴粘。", {icon: 1});

        }

    </script>
</body>
</html>
